home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS26.ADF
/
HexDump
/
HexDump.mod
< prev
next >
Wrap
Text File
|
1989-01-26
|
7KB
|
223 lines
MODULE HexMemoryDump;
(* This program dumps the hex listing of memory. *)
FROM InOut IMPORT WriteString, WriteLn, WriteCard,
Read, EOL;
FROM LongInOut IMPORT WriteLongCard, WriteLongHex;
FROM Strings IMPORT Length;
FROM SYSTEM IMPORT BYTE, LONGWORD, ADDRESS, TSIZE;
TYPE
LocationType = ARRAY[0..79] OF CHAR;
CharType = ARRAY[1..16] OF CHAR;
VAR
StartingLocation : LocationType;
EndingLocation : LocationType;
Start : LONGCARD;
End : LONGCARD;
Delta : LONGCARD;
StartDump : LONGWORD;
StartDumpPtr : ADDRESS;
LeftByte : CARDINAL;
RightByte : CARDINAL;
CharOut : CharType;
CharIndex : CARDINAL;
PROCEDURE ReadInput(VAR Input : LocationType); (* Input/Output *)
(* This procedure reads an input string typed in from the
keyboard. *)
VAR
x : CARDINAL;
ch : CHAR;
BEGIN
x := 0;
LOOP
(* Read the character and captialize. *)
Read(ch);
Input[x] := CAP(ch);
(* If EOL or max length of 80 then exit the loop. *)
IF ((ch = EOL) OR (x = 79)) THEN
EXIT;
ELSE
x := x + 1;
END; (* IF *)
END; (* LOOP *)
END ReadInput;
PROCEDURE ConvertHexStringToCardinal(VAR Num : LONGCARD;
NumLocation : LocationType);
(* This procedure converts the hex input string to cardinal in
order to convert to an address. *)
VAR
Index : INTEGER;
Temp : CARDINAL;
Temp1 : LONGCARD;
Dummy : CHAR;
MaxCount : INTEGER;
BEGIN
Index := 0;
MaxCount := Length(NumLocation) - 1;
WHILE Index < MaxCount DO
Dummy := NumLocation[Index];
IF((Dummy >= 'A') AND (Dummy <= 'F')) THEN
Temp := ORD(Dummy) - ORD('A') + 10;
ELSE
Temp := ORD(Dummy) - ORD('0');
END;(* IF *)
Temp1 := LONGCARD(Temp);
Num := 16 * Num + Temp1;
Index := Index + 1;
END; (* WHILE *)
END ConvertHexStringToCardinal;
PROCEDURE HexDump( StartAddress : ADDRESS;
WordCount : LONGCARD);
(* This procedure dumps memory in hex. *)
VAR
loc : ADDRESS;
count : LONGCARD;
BEGIN
loc := StartAddress;
FOR count := 1 TO WordCount DO
(* Write the line starting address and keep line to a length
of eight.*)
IF count MOD 8 = 1 THEN
WriteString(CharOut);
WriteLn;
WriteLongHex(LONGCARD(loc),8);
WriteString(': ');
END;(* IF *)
(* Write the hex value of memory. *)
WriteHex(CARDINAL(loc^),LeftByte,RightByte);
INC(loc,TSIZE(CARDINAL))
END;(* FOR *)
WriteLn;
RETURN;
END HexDump;
PROCEDURE WriteHex( Input : CARDINAL;
VAR LeftByte : CARDINAL;
VAR RightByte : CARDINAL);
(* This procedure writes out the memory contents in hex. *)
TYPE
OutType = ARRAY[0..3] OF CHAR;
DivisorType = ARRAY[0..3] OF CARDINAL;
VAR
Out : OutType;
Index : CARDINAL;
Temp : CARDINAL;
Divisor : DivisorType;
x : CARDINAL;
PROCEDURE HexOut(Temp : CARDINAL;
VAR Out : OutType;
Index : CARDINAL);
(* This procedure converts memory contents to hex. *)
BEGIN
CASE Temp OF
0 : Out[Index] := '0' |
1 : Out[Index] := '1' |
2 : Out[Index] := '2' |
3 : Out[Index] := '3' |
4 : Out[Index] := '4' |
5 : Out[Index] := '5' |
6 : Out[Index] := '6' |
7 : Out[Index] := '7' |
8 : Out[Index] := '8' |
9 : Out[Index] := '9' |
10 : Out[Index] := 'A' |
11 : Out[Index] := 'B' |
12 : Out[Index] := 'C' |
13 : Out[Index] := 'D' |
14 : Out[Index] := 'E' |
15 : Out[Index] := 'F';
END; (* CASE *)
RETURN;
END HexOut;
BEGIN
Divisor[0] := 4096;
Divisor[1] := 256;
Divisor[2] := 16;
Divisor[3] := 1;
FOR Index := 0 TO 3 DO
IF Index = 2 THEN
RightByte := Input;
LeftByte := 0;
FOR x := 0 TO 1 DO
IF((Out[x] >= 'A') AND (Out[x] <= 'F')) THEN
LeftByte := 16 * LeftByte + (ORD(Out[x]) -
ORD('A') + 10);
ELSE
LeftByte := 16 * LeftByte + ORD(Out[x]) - ORD('0');
END; (* IF *)
END; (* FOR *)
END; (* IF *)
Temp := Input DIV Divisor[Index];
HexOut(Temp,Out,Index);
Input := Input - Temp * Divisor[Index];
END; (* FOR *)
WriteChar(CharOut,CharIndex,LeftByte,RightByte);
WriteString(Out);
WriteString(' ');
END WriteHex;
PROCEDURE WriteChar(VAR CharOut : CharType;
VAR CharIndex : CARDINAL;
LeftByte : CARDINAL;
RightByte : CARDINAL);
(* This procedure writes out the ASCII equivalent of the memory
contents. *)
BEGIN
IF((CHR(19H)<CHR(LeftByte))AND(CHR(LeftByte)<CHR(7EH))) THEN
CharOut[CharIndex] := CHR(LeftByte);
ELSE
CharOut[CharIndex] := CHR(2EH);
END; (* IF *)
CharIndex := CharIndex + 1;
IF((CHR(19H)<CHR(RightByte))AND(CHR(RightByte)<CHR(7EH))) THEN
CharOut[CharIndex] := CHR(RightByte);
ELSE
CharOut[CharIndex] := CHR(2EH);
END; (* IF *)
CharIndex := CharIndex + 1;
IF CharIndex = 17 THEN CharIndex := 1 END;
END WriteChar;
BEGIN
(* Initialize parameters. *)
Start := 0;
CharIndex := 1;
(* Get starting memory location. *)
WriteString('Enter starting memory location: ');
ReadInput(StartingLocation);
(* Convert to value. *)
ConvertHexStringToCardinal(Start,StartingLocation);
(* Get ending memory location. *)
WriteString('Enter ending memory location: ');
ReadInput(EndingLocation);
(* Convert to value. *)
ConvertHexStringToCardinal(End,EndingLocation);
(* Calculate number of bytes to output. *)
Delta := (End - Start) DIV 2;
(* Calculate starting address. This is important. *)
StartDump := LONGWORD(Start);
StartDumpPtr := ADDRESS(StartDump);
(* Dump memory. *)
HexDump(StartDumpPtr,Delta);
END HexMemoryDump.